<template>
    <el-container class="home">
        <el-header>
            <div class="logo">
                <img src="../assets/img/heima.png" alt="">
                <p>电商后台管理系统</p>
            </div>
            <el-button type="info" @click="logout">登出</el-button>
        </el-header>
        <el-container class="fiex-container">
            <el-aside :width="isCollapse ? '64px':'200px'">
                <div class="collapseCtrl" @click="isCollapse = !isCollapse">
                    <i v-if="isCollapse" class="el-icon-s-unfold"></i>
                    <i v-else class="el-icon-s-fold"></i>
                </div>
                <el-menu
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
                :collapse="isCollapse"
                :collapse-transition="false"
                :router="true"
                :default-active="$route.path"
                >
                    <el-submenu :index="item.id+''" v-for="item in menu" :key="item.id">
                        <template slot="title">
                            <i :class="iconsObj[item.path]"></i>
                            <span>{{item.authName}}</span>
                        </template>
                        <el-menu-item :index="'/'+items.path" v-for="items in item.children" :key="items.id">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>{{items.authName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside> 
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
        
    </el-container>
</template>

<script>
import { getMenus } from "../request/api";

export default {
    name: "home",
    data(){
        return{
            menu:{},
            iconsObj:{
                users: 'el-icon-s-custom',
                rights: 'el-icon-s-tools',
                goods: 'el-icon-s-goods',
                orders: 'el-icon-s-order',
                reports: 'el-icon-s-data'
            },
            isCollapse: false
        }
    },
    created(){
        this.getMenu()
    },
    mounted(){
        
    },
    methods:{
        logout(){
            localStorage.removeItem('token');
            this.$router.push('/login')
        },
        getMenu(){
            getMenus().then(res => {
                if(res.meta.status == 200){
                    this.menu = res.data;
                }else{
                    this.$message.error(res.meta.msg);
                    return false;
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.home{
    height: 100%;
}
.el-header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #373d41;
    .logo{
        display: flex;
        align-items: center;
        img{
            height: 40px;
        }
        p{
            margin-left: 15px;
            color: #ccc;
        }
    }
    .el-button{
        padding: 8px 12px;
    }
}
.fiex-container{
    height: calc( 100% - 60px);
}
.el-aside{
    background-color: #333744;
    .collapseCtrl{
        color: #ccc;
        text-align: center;
        background-color: #4a5064;
        cursor: pointer;
    }
    .el-menu{
        border-right: 0;
    }
}
.el-main{
    background-color: #eaedf1;
}
</style>